package com.hiwhitley.easy.day12;

/**
 * Created by hiwhitley on 2016/8/16.
 */
public class ReverseVowels {
    public static String reverseVowels(String s) {
        if (s == null || s.length() == 1)
            return s;
        char[] origin = s.toCharArray();
        int left = 0, right = origin.length - 1;
        char tmp;
        while (left < right) {
            if (!isVowels(origin[left])) {
                left++;
                continue;
            }
            if (!isVowels(origin[right])) {
                right--;
                continue;
            }
            tmp = origin[left];
            origin[left] = origin[right];
            origin[right] = tmp;
            left++;
            right--;
        }
        return String.valueOf(origin);

    }

    private static boolean isVowels(char cc) {
        return cc == 'a' || cc == 'e' || cc == 'i' || cc == 'o' || cc == 'u' || cc == 'A' || cc == 'E' || cc == 'I' || cc == 'O' || cc == 'U';
    }


    public static void main(String[] args) {
        System.out.println(reverseVowels("leetcode"));
    }

}
